package org.jeecg.modules.mall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.mall.entity.TbMnAdzone;
import org.jeecg.modules.mall.entity.TbMnUser;
import org.jeecg.modules.mall.mapper.TbMnAdzoneMapper;
import org.jeecg.modules.mall.service.ITbMnAdzoneService;
import org.jeecg.modules.mall.service.ITbMnUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: tb_mn_adzone
 * @Author: jeecg-boot
 * @Date:   2020-05-12
 * @Version: V1.0
 */
@Service
public class TbMnAdzoneServiceImpl extends ServiceImpl<TbMnAdzoneMapper, TbMnAdzone> implements ITbMnAdzoneService {

    @Autowired
    @Lazy(true)
    private ITbMnUserService tbMnUserService;

    @Override
    public TbMnUser getOneByAdzone(String adzoneId) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("adzone_id",adzoneId);
        TbMnAdzone  TbMnAdzone= this.baseMapper.selectOne(queryWrapper);
        if(null!=TbMnAdzone){
            String userId=TbMnAdzone.getAccount();
              TbMnUser tbMnUser= tbMnUserService.getById(userId);
              return tbMnUser;
        }

        return null;
    }

    @Override
    public IPage<TbMnAdzone> pageAndUserData(Page<TbMnAdzone> page, TbMnAdzone tbMnAdzone) {
        return page.setRecords(this.baseMapper.pageAndUserData(page, tbMnAdzone));
    }
}
